//
//  UIDevice+File.m
//  XYuanTiKu
//
//  Created by mayanwei on 15-6-24.
//  Copyright (c) 2015年 XiongYing Tec. All rights reserved.
//

#import "UIDevice+File.h"
#include <sys/param.h>
#include <sys/mount.h>

@implementation UIDevice (File)

+ (long long)freeSpace
{
    struct statfs buf;
    long long freespace = -1;
    if(statfs("/private/var", &buf) >= 0){
        freespace = (long long)buf.f_bsize * buf.f_bfree;
    }
    
    return freespace / 1024;
}

+ (long long)getTotalDiskSpaceInKB
{
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    struct statfs tStats;
    statfs([[paths lastObject] cString], &tStats);
    long long totalSpace = (long long)(tStats.f_blocks * tStats.f_bsize);
    
    return totalSpace / 1024;
}

@end
